/*
 * File Name:               XBehaviorTree.cs
 * 
 * Description:             普通类
 * Author:                  lisiyu <576603306@qq.com>

 * Create Date:             2017/06/13
 */

using BehaviorDesigner.Runtime.Tasks;
using System.Reflection;
using System;

namespace XBehaviorTree
{ 
    [System.Serializable]
    public class XBehaviorTree
    {
        public ITask_BTree mTask;
        public TaskStatus OnUpdate()
        {
            if (mTask == null)
                return TaskStatus.Failure;
            else
            {
#if XBTREE_DEBUG
                return (mTask as ITask_Debug).OnDebugUpdate();
#else
                return mTask.OnUpdate();
#endif
            }
        }

        public static ITask_BTree parse(Task task)
        {
            if(task is Sequence)
            {
                return Sequence_BTree.parse(task as Sequence);
            }
            else if (task is Selector)
            {
                return Selector_BTree.parse(task as Selector);
            }
            else if (task is Inverter)
            {
                return Inverter_BTree.parse(task as Inverter);
            }
            else
            {
                return task as ITask_BTree;
            }
        }
    }
}
